<?php

/*
 * This file is part of the yuki package.
 * Copyright (c) 2011 olamedia <olamedia@gmail.com>
 *
 * Licensed under The MIT License
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * yLogMessage
 *
 * @package yuki
 * @subpackage log
 * @version SVN: $Id: yLogMessage.php 149 2011-02-20 06:58:24Z olamedia@gmail.com $
 * @revision SVN: $Revision: 149 $
 * @date $Date: 2011-02-20 06:58:24 +0000 (Sun, 20 Feb 2011) $
 * @author olamedia
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
class yLogMessage{
    const
    EMERGENCY = 0, // System is unusable
    ALERT = 1, // Immediate action required
    CRITICAL = 2, // Critical conditions
    ERROR = 3, // Error conditions
    WARNING = 4, // Warning conditions
    NOTICE = 5, // Normal but significant
    INFO = 6, // Informational
    DEBUG = 7; // Debug-level messages
    protected static $_priorityNames = array(
        self::EMERGENCY=>'emerg',
        self::ALERT=>'alert',
        self::CRITICAL=>'crit',
        self::ERROR=>'error',
        self::WARNING=>'warn',
        self::NOTICE=>'notice',
        self::INFO=>'info',
        self::DEBUG=>'debug'
    );
    public $message = '';
    public $priority = 'info';
    public $time = null;
    /**
     * Constructor.
     * @param string $message
     * @param int $priority 
     */
    public function __construct($message, $priority){
        $this->message = $message;
        $this->priority = $priority;
        $this->time = microtime(true);
    }
    /**
     * Gets priority name.
     * @return string
     */
    public function getPriorityName(){
        return self::$_priorityNames[$this->priority];
    }
    /**
     * Returns string in format "d.m.Y H:i:s [priopity] message"
     * @magic
     * @return string
     */
    public function __toString(){
        return (string) date("d.m.Y H:i:s", intval($this->time)).' ['.$this->getPriorityName().'] '.$this->message;
    }
}

